﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Security.Cryptography.X509Certificates;

namespace NHINDirect
{
    public class NHINDAddress : MailAddress
    {
        X509Certificate2 m_certificate;
        TrustEnforcementStatus m_trustStatus;
        X509Certificate2Collection m_trustAnchors;
                
        public NHINDAddress(string address)
            : this(address, null)
        {
        }

        public NHINDAddress(MailAddress address)
            : this(address.ToString())
        {
        }

        public NHINDAddress(string address, X509Certificate2 certificate)
            : base(address)
        {            
            this.m_certificate = certificate;
        }
        
        public X509Certificate2 Certificate
        {
            get
            {
                return this.m_certificate;
            }
            set
            {
                this.m_certificate = value;
            }
        }
        
        public bool HasCertificate
        {
            get
            {
                return (this.m_certificate != null);
            }
        }
        
        public X509Certificate2Collection TrustAnchors
        {
            get
            {
                return this.m_trustAnchors;
            }
            set
            {
                this.m_trustAnchors = value;
            }
        }
        
        public bool HasTrustAnchors
        {
            get
            {
                return (this.m_trustAnchors != null && this.m_trustAnchors.Count > 0);
            }
        }
        
        public TrustEnforcementStatus Status
        {
            get
            {
                return this.m_trustStatus;
            }
            set
            {
                this.m_trustStatus = value;
            }
        }            
        
        public bool IsTrusted(TrustEnforcementStatus minTrustStatus)
        {
            return (this.m_trustStatus >= minTrustStatus);
        }
    }    
}
